<!DOCTYPE html>
<html>
  <head>
    <title>Test Case For user-agent!</title>
  </head>
  <body>
    <h1>Hello User-Agent<h1/>
    <script>
    //data[0]: original
    //data[1]: child window
    //data[2]: reload(0)
    //data[3]: reload(1)
    //data[4]: reload(2)
    //data[5]: reload(3)
    var gui = require('nw.gui');
    var user_agent = navigator.userAgent.split('/');
    var win = gui.Window.get();
    if (localStorage.user_agent_count == undefined) {
        var child = window.open("index1.html");
	localStorage.child_window_user_agent = "";
	function test() {
	    if (localStorage.child_window_user_agent == "")
		setTimeout(test, 1000);
	    else {
                win.reload(0);
	    }
	}
        localStorage.user_agent_count = 0;
        localStorage.user_agent = user_agent;
	test();	    
    } else if (localStorage.user_agent_count == 0) {
	localStorage.user_agent_count++;
	localStorage.user_agent += '*' + user_agent;
	win.reload(1);
    } else if (localStorage.user_agent_count == 1) {
	localStorage.user_agent_count++;
	localStorage.user_agent += '*' + user_agent;
	win.reload(2);
    } else if (localStorage.user_agent_count == 2) {
	localStorage.user_agent_count++;
	localStorage.user_agent += '*' + user_agent;
	win.reload(3);
    } else if (localStorage.user_agent_count == 3) {
	localStorage.user_agent_count++;
	localStorage.user_agent += '*' + user_agent;
	data = localStorage.user_agent.split('*');
	delete localStorage.user_agent_count;
	delete localStorage.user_agent;
	delete localStorage.child_window_user_agent;

    var socket = require('net').connect({port: 13013});
    socket.setEncoding('utf8');
    socket.end(JSON.stringify(data));

    }
    </script>
  </body>
</html>
